<?php

/**
 * This is the model class for table "company_contacts".
 */
class company_address_contacts extends company_contacts
{
	/**
	 * The followings are the available columns in table 'company_contacts':
	 * @var integer $id
	 * @var integer $company_id
	 * @var string $type
	 * @var string $ref
	 * @var integer $member_id
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return company_contacts the static model class
	 */
	public $teleType = array("General"=>'General',"Sales"=>'Sales',"Account"=>'Account',"Warehouse"=>"Warehouse","General fax"=>'General fax',"Sales fax"=>'Sales fax',"Account fax"=>'Account fax',"Warehouse fax"=>'Warehouse fax',"Others"=>'Others');
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('foreign_key', 'numerical', 'integerOnly'=>true),
			array('type, ref', 'length', 'max'=>25),
			array('for_model', 'length', 'max'=>50),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, type, ref, for_model, foreign_key', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type' => 'Type',
			'ref' => 'Ref',
			'member_id' => 'Member',
		);
	}
	
	public function deleteAll($condition,$params=array()) {
		if(!empty($condition))
			$condition .= " and";
		$condition.=" for_model = 'address'";
		return parent::deleteAll($condition,$params);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('company_id',$this->company_id);

		$criteria->compare('type',$this->type,true);

		$criteria->compare('ref',$this->ref,true);

		$criteria->compare('member_id',$this->member_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}